

# url = "https://chat.openai.com/"

import webbrowser
import pyautogui
import time
import tkinter
import os
import pandas as pd
import pyperclip
from utils import lvjy_pygui,paddle_ocr_mkdnn,text_xy_chatgpt_web



def get_pages():  # 打开页面并截图
    
    url="https://chat.openai.com/"
    webbrowser.open(url)
    time.sleep(5)  # wait for the page to load
    pyautogui.press('F11')
    time.sleep(1.5)  # wait for the page to load

    lvjy_pygui.screenshot_and_save()
    res_dict = paddle_ocr_mkdnn.ocr_img()
    return res_dict
    # text_list = list(res_dict.keys())
    # print(text_list[:10])
    # --------------------------------------------------- 选择正序排列

def prepare():
    d = get_pages()  # 获取主页的坐标信息
    [x,y] = text_xy_chatgpt_web.parse_dict(d,text='maxjax语法糖')
    lvjy_pygui.move_click(x,y,click_wait=2)  # 选择maxjax语法糖的窗口

    
    # print(promp_text)
    [x,y] = text_xy_chatgpt_web.parse_dict(d,text='发送消息给ChatGPT...')
    lvjy_pygui.move_click(x,y,click_wait=0.5)  # 回到对话窗口 
    
    promp_text = open('prompts/01_数学物理推理证明.txt', 'r', encoding='utf-8').read()

    # 将文本内容复制到剪贴板
    pyperclip.copy(promp_text)
    time.sleep(0.5)

    # 使用pyautogui模拟按下Ctrl+V（粘贴）
    pyautogui.hotkey('ctrl', 'v')

    pyautogui.press('enter')

    time.sleep(10)      # 等待学些
    pyautogui.scroll(30000)

    # 再次识别等待回答
    lvjy_pygui.screenshot_and_save()
    res_dict = paddle_ocr_mkdnn.ocr_img()











def run():
    prepare()
    # get_pages()




    pass



if __name__=='__main__':
    run()